<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\UserSubscribe;
use App\Shop;
use App\UserInfo;

class UserSubscribeController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //查询所有的信息
        $datas = UserSubscribe::select('shops.shopname','user_subscribe.id','user_subscribe.mobile','user_subscribe.starttime','user_subscribe.endtime','user_subscribe.substatus')
            ->join('shops','shops.shopid','=','user_subscribe.shopid')
            ->paginate('30');
        return view('admin.usubscribe.index',compact('datas'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //根据id获取数据
        $datas = UserSubscribe::select('user_subscribe.*','shops.shopname','shops_master.nickname')
            ->join('shops','shops.shopid','=','user_subscribe.shopid')
            ->join('shops_master','shops_master.hmid','=','user_subscribe.hmid')
            ->first();
      return view('admin.usubscribe.show',compact('datas'));

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //获取id;直接删除
        $res = UserSubscribe::destroy($id);
        if($res)
        return Response() -> json(['status'=>'success','msg'=>'删除成功']);
        return Response() -> json(['status'=>'error','msg'=>'删除失败']);
    }
}
